package com.ruoyi.module.courseDetail.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.module.course.domain.Course;
import com.ruoyi.module.course.mapper.CourseMapper;
import com.ruoyi.module.courseDetail.domain.CourseDetail;
import com.ruoyi.module.courseDetail.mapper.CourseDetailMapper;
import com.ruoyi.module.courseDetail.service.ICourseDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程详情Service业务层处理
 * 
 * @author yqq
 * @date 2024-05-06
 */
@Service
public class CourseDetailServiceImpl implements ICourseDetailService 
{
    @Resource
    private CourseDetailMapper courseDetailMapper;

    @Resource
    private CourseMapper courseMapper;

    /**
     * 查询课程详情
     * 
     * @param detailId 课程详情主键
     * @return 课程详情
     */
    @Override
    public CourseDetail selectCourseDetailByDetailId(Long detailId)
    {
        return courseDetailMapper.selectCourseDetailByDetailId(detailId);
    }

    /**
     * 查询课程详情列表
     * 
     * @param courseDetail 课程详情
     * @return 课程详情
     */
    @Override
    public List<CourseDetail> selectCourseDetailList(CourseDetail courseDetail)
    {
        return courseDetailMapper.selectCourseDetailList(courseDetail);
    }

    /**
     * 新增课程详情
     * 
     * @param courseDetail 课程详情
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertCourseDetail(CourseDetail courseDetail)
    {
        Course course = new Course();
        course.setCourseId(courseDetail.getdCourseId());
        course.setUpdateTime(DateUtils.getNowDate());
        courseMapper.updateCourse(course);
        courseDetail.setCreateTime(DateUtils.getNowDate());
        return courseDetailMapper.insertCourseDetail(courseDetail);
    }

    /**
     * 修改课程详情
     * 
     * @param courseDetail 课程详情
     * @return 结果
     */
    @Override
    public int updateCourseDetail(CourseDetail courseDetail)
    {
        courseDetail.setUpdateTime(DateUtils.getNowDate());
        return courseDetailMapper.updateCourseDetail(courseDetail);
    }

    /**
     * 批量删除课程详情
     * 
     * @param detailIds 需要删除的课程详情主键
     * @return 结果
     */
    @Override
    public int deleteCourseDetailByDetailIds(Long[] detailIds)
    {
        return courseDetailMapper.deleteCourseDetailByDetailIds(detailIds);
    }

    /**
     * 删除课程详情信息
     * 
     * @param detailId 课程详情主键
     * @return 结果
     */
    @Override
    public int deleteCourseDetailByDetailId(Long detailId)
    {
        return courseDetailMapper.deleteCourseDetailByDetailId(detailId);
    }
}
